using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;

namespace Tourreau.Gilles.FaxDotNet.Demo
{
    internal partial class FaxConnection : Form
    {
        private FaxServer faxServer;

        private FaxConnection()
        {
            InitializeComponent();

            foreach(string printer in PrinterSettings.InstalledPrinters)
                this.faxPrinter.Items.Add(printer);
        }

        public static FaxServer Connect()
        {
            using (FaxConnection f = new FaxConnection())
            {
                if (f.ShowDialog() == DialogResult.OK)
                    return f.faxServer;
            }

            return null;
        }

        private void OnOKClick(object sender, EventArgs e)
        {
            if (this.faxPrinter.SelectedIndex == -1)
            {
                FaxMessageBox.Error(FaxResources.NoFaxPrinterSelected);
                this.DialogResult = DialogResult.None;
                return;
            }

            if (FaxServer.TestConnection(this.serverName.Text) == true)
                this.faxServer = new FaxServer(this.serverName.Text, (string)this.faxPrinter.SelectedItem);
            else
            {
                FaxMessageBox.Error(FaxResources.UnableToConnect, this.faxServer);
                this.DialogResult = DialogResult.None;
            }
        }
    }
}